%% case 6, dXt=sin(exp(t))dW 
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=6;
% index J for X
alphaK=50; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% time T
T = 1;
% time mesh 
num=50; tspan = linspace(0,T,num+1);
% construct orthogoal basis in L2[0,t]
orthbasis(T); msvalue(T,num);
% sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
options = [];
row=size(alphas,1); X0=zeros(row,1);
% solver of X
disp('solving X')
tic
[time,X] = ode45(@randomtest,tspan,X0,options,T,'single',casenum,num,alphaK);
toc
varitest(time,X.*X,T,'single',casenum,num)

%% case5, dXt=sin(exp(5t))dW 
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=5;
% index J for X
alphaK=200; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% time T
T = 1;
% time mesh 
num=200; tspan = linspace(0,T,num+1);
% construct orthogoal basis in L2[0,t]
orthbasis(T); msvalue(T,num);
% sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
options = [];
row=size(alphas,1); X0=zeros(row,1);
% solver of X
disp('solving X')
tic
[time,X] = ode45(@randomtest,tspan,X0,options,T,'single',casenum,num,alphaK);
toc
varitest(time,X.*X,T,'single',casenum,num)

%% 4th case dX=sin(30t)dW
% this case is worth study. term 20 with num=50 is bad for T=1 good for
% T=0.5; term 40 with num=50 is bad for T=1. term 40 with num = 100 spend
% 16 seconds is good for T=1
clear all
casenum=4;
% index J for X
alphaK=40; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% time T
T = 1;
% time mesh 
num=100; tspan = linspace(0,T,num+1);
% construct orthogoal basis in L2[0,t]
orthbasis(T); msvalue(T,num);
% sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
options = [];
row=size(alphas,1); X0=zeros(row,1);
% solver of X
disp('solving X')
tic
[time,X] = ode45(@randomtest,tspan,X0,options,T,'single',casenum,num,alphaK);
toc
varitest(time,X.*X,T,'single',casenum,num)

%% 3rd case, dX=sin(5t)dW, (sigma(t)=sin(5t))
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=3;
% index J for X
alphaK=20; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% time T
T = 1;
% time mesh 
num=50; tspan = linspace(0,T,num+1);
% construct orthogoal basis in L2[0,t]
orthbasis(T); msvalue(T,num);
% sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
options = [];
row=size(alphas,1); X0=zeros(row,1);
% solver of X
disp('solving X')
tic
[time,X] = ode45(@randomtest,tspan,X0,options,T,'single',casenum,num,alphaK);
toc
varitest(time,X.*X,T,'single',casenum,num)

%% 2nd case, dX=sin(t)dW, (sigma(t)=sin(t)) 
%the revisible part are K,N,RNK, R(s), sigma(s), y0, tspan
clear all
casenum=2;
% index J for X
alphaK=15; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% time T
T = 1;
% time mesh 
num=50; tspan = linspace(0,T,num+1);
% construct orthogoal basis in L2[0,t]
orthbasis(T); msvalue(T,num);
% sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
options = [];
row=size(alphas,1); X0=zeros(row,1);
% solver of X
disp('solving X')
tic
[time,X] = ode45(@randomtest,tspan,X0,options,T,'single',casenum,num,alphaK);
toc
varitest(time,X.*X,T,'single',casenum,num)

%% 1st case, dX=dW, (sigma(t)==const 1)
clear all
casenum=1;
% index J for X
alphaK=10; alphas=[zeros(1,alphaK);eye(alphaK)];
fname='alphas'; save(fname,'alphas');
% time T
T = 1;
% time mesh 
num=50; tspan = linspace(0,T,num+1);
% construct orthogoal basis in L2[0,t]
orthbasis(T); msvalue(T,num);
% sigma
%options = odeset('AbsTol',1e-12,'RelTol',1e-6);
options = [];
row=size(alphas,1); X0=zeros(row,1);
% solver of X
disp('solving X')
tic
[time,X] = ode45(@randomtest,tspan,X0,options,T,'single',casenum,num,alphaK);
toc
varitest(time,X.*X,T,'single',casenum,num)